<?php

namespace App\Services\Admin;

use App\Models\UserRank;

class Level extends Base
{
    public static function index($where=[])
    {
        return (new UserRank())->where($where)->orderBy('id','desc');
    }

    public static function info($id)
    {
        return (new UserRank())->where('id', $id)->first();
    }

    public static function add($param = [])
    {
        $rank_min = self::index()->orderBy('rank_min','desc')->value('rank_min');

        if($param['rank_min'] <= $rank_min)throw new \Exception('不能低於最高等級的分數!');

        return (new UserRank())->insert($param);
    }

    public static function edit($id , $param=[])
    {
        return (new UserRank())->where('id',$id)->update($param);
    }

    public static function del($id)
    {
        return (new UserRank())->where('id', $id)->delete();
    }
}
